package com.xiaomage.view.draw5

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.view.View

/**
 * Created by Administrator on 2018/1/2.
 */
class DrawTextView4(context: Context): View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        var y=0f
        val centerY=200f

        val paint= Paint()
        paint.isAntiAlias=true
        paint.style= Paint.Style.STROKE
        paint.color= Color.RED
        paint.textSize=120f

        //画中线
        canvas.drawLine(0f,centerY,1000f,centerY,paint)
        //求基线baselineY=(2*centery-bottom-top)/2
        val fm=paint.fontMetrics
        y=(centerY*2-fm.bottom-fm.top)/2
        canvas.drawText("XiaoMage",200f,y,paint)




    }
}